﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MBSVO;

namespace MBS.UserControls.CinemaUserControl
{
    
    public partial class ViewCinemaControl : System.Web.UI.UserControl
    {
        #region transfer
        MBSBLC.BLC cinemablc = new MBSBLC.BLC();

        public delegate void RemoveCinemaHandler();

        public event RemoveCinemaHandler RemoveCinemaSuccesull;
        public event RemoveCinemaHandler RemoveCinemaFailed;


        public delegate void CinemaUpdateHandler();

        public event CinemaUpdateHandler CinemaUpdateComplete;
        public event CinemaUpdateHandler CinemaUpdateFailed;

        private bool actionresult;
        public bool Actionresult
        {
            get { return actionresult; }
            set { actionresult = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CinemaList1.LoadDropDownBox();
                loadCinemaDetail(CinemaList1.GetSelectedValue());
            }

            CinemaList1.CimeListChanged += new CinemaList.CinemaListHandler(CinemaList1_CimeListChanged);
            
        }

        void CinemaList1_CimeListChanged(int SelectedValue)
        {
            loadCinemaDetail(SelectedValue);
        }

        protected void DeleteCinemaBtn_Click(object sender, EventArgs e)
        {
            actionresult = cinemablc.DeleteCinema(CinemaList1.GetSelectedValue());
            if (actionresult)
            {
                RemoveCinemaSuccesull();
                CinemaList1.LoadDropDownBox();
            }

            else
            {
                RemoveCinemaFailed();
            }
        }

        void loadCinemaDetail(int SelectedValue)
        {
            CinemaVO cinemaVO = cinemablc.GetCinemaByID(SelectedValue);
            Label6.Text = ""+cinemaVO.CinemaID;
            TextBox3.Text = cinemaVO.CinemaName;
            TextBox1.Text = cinemaVO.Location;
            TextBox2.Text = "" + cinemaVO.NumOfScreens;
        }



        protected void Button1_Click(object sender, EventArgs e)
        {


            actionresult = cinemablc.UpdateCinema(TextBox3.Text.ToString(), TextBox1.Text.ToString(), TextBox2.Text.ToString());
            if (actionresult)
            {
                CinemaList1.CinemaID = CinemaList1.GetSelectedValue();
                loadCinemaDetail(CinemaList1.CinemaID);
                CinemaUpdateComplete();
            }
            else
            {
                CinemaUpdateFailed();
            }


        }

    #endregion
    }
}